import pygame

from dialog.tunnel_dialog import TunnelTask4EndDialog, TunnelTask4BeginDialog, TunnelTaskFailDialog
from scene.task.stage_one import TaskStatus
from scene.task.stage_one.task2_kill_japanese import KillJapaneseTask

"""
任务4实现类(继承任务2)
"""
class KillJapaneseTaskAll(KillJapaneseTask):

    def __init__(self, xiao_tie, japanese, font):
        """
        参数初始化
        :param xiao_tie:
        :param japanese:
        :param font:
        """
        super().__init__(xiao_tie, japanese, font)

    def init_dialog(self):
        """
        对话初始化
        :return:
        """
        self.task_dialog = TunnelTask4BeginDialog(self.font)
        self.win_dialog = TunnelTask4EndDialog(self.font)
        self.fail_dialog = TunnelTaskFailDialog(self.font)

    def __do_self_task(self, key_down, key_list):
        """
        任务具体内容
        :param key_down:
        :param key_list:
        :return:
        """
        self.do_collide_group()
        collisions = pygame.sprite.groupcollide(self.mines, self.japanese, True, True)
        self.__task_need(collisions)
        # 埋地雷
        if key_down and key_list[pygame.K_SPACE]:
            self.create_mine(self.xiao_tie.pos_x, self.xiao_tie.pos_y)
        for boom in self.booms:
            if boom.kill_flag():
                self.booms.remove(boom)

    def __task_need(self, collisions):
        """
        任务要求
        :param collisions: 碰撞集合
        :return:
        """
        for wall in collisions:
            self.sound1.play()
            self.create_boom(wall.rect.x - wall.rect.width,
                               wall.rect.y - wall.rect.height)
            self.score += 1
            if self.score >= 3:
                self.task_status = TaskStatus.stage_win

    def do_collide_group(self):
        super().do_collide_group()

